import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/Table';
import { render } from '@apps/antd-admin/src/hooks/render/renderUtils';
import { RenderType } from '@pkg/setting';
import {Api } from './api';
import { categoryList } from '../category/api';
import { rules } from '@pkg/utils';
export const columns: BasicColumn[] = [
  {
    title: '商品名称',
    dataIndex: 'goodsName',
    width: 120,
  },
  {
    title: '商品封面',
    dataIndex: 'coverImg',
    width: 90,
    customRender: render.renderImage,
  },
  {
    title: '商品类型',
    dataIndex: 'categoryName',
    width: 100,
  },
  {
    title: '面值',
    dataIndex: 'goodsPrice',
    width: 120,
  },
  {
    title: '使用门槛',
    dataIndex: 'hasWithAmount',
    width: 80,
    dictData: [
      { label: '有', value: 1 },
      { label: '无', value: 0 },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '最低使用金额',
    dataIndex: 'withAmount',
    width: 120,
  },
  {
    title: '兑换积分',
    dataIndex: 'integralValue',
    width: 120,
  },
  {
    title: '上架',
    dataIndex: 'isShelf',
    width: 100,
    rowKey: 'goodsId',
    renderApi: Api.setIsShelf,
    customRender: render.renderSwitch,
  },
  {
    title: '推荐至签到页面',
    dataIndex: 'isHomeRecommend',
    width: 100,
    rowKey: 'goodsId',
    renderApi: Api.setIsHomeRecommend,
    customRender: render.renderSwitch,
  },
  {
    title: '已兑换数量',
    dataIndex: 'countNum',
    width: 120,
  },
  {
    title: '剩余数量',
    dataIndex: 'inventory',
    width: 120,
  },
  {
    title: '开始日期',
    dataIndex: 'expiryBeginTime',
    width: 120,
  },
  {
    title: '截止日期',
    dataIndex: 'expiryEndTime',
    width: 120,
  },
  {
    title: '有效天数',
    dataIndex: 'validDay',
    width: 80,
  },
  {
    title: '创建日期',
    dataIndex: 'createTime',
    width: 120,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'goodsName',
    label: '商品名称',
    component: 'Input',
    colProps: { span: 5 },
  },
  {
    field: 'categoryId',
    label: '商品类型',
    component: 'ApiSelect',
    colProps: { span: 5 },
    componentProps: {
      api: categoryList,
      labelField: 'categoryName',
      valueField: 'categoryId',
      immediate: true,
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '商品名称',
    field: 'goodsName',
    component: 'Input',
    required: true,
  },
  {
    label: '商品类型',
    field: 'categoryId',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: categoryList,
      params: { handlerName: 'busCategoryOtherListHandler' },
      labelField: 'categoryName',
      valueField: 'categoryId',
      immediate: true,
    },
  },
  {
    label: '面值',
    field: 'goodsPrice',
    required: true,
    component: 'InputNumber',
    componentProps:{
      style:{
        width:'200px'
      }
    },
  },
  {
    field: 'hasWithAmount',
    label: '使用门槛',
    component: 'RadioGroup',
    required: true,
    componentProps: {
      options: [
        { label: '有', value: 1 },
        { label: '无', value: 0 },
      ],
    },
  },
  {
    label: '最低使用金额',
    field: 'withAmount',
    required: true,
    component: 'InputNumber',
    componentProps:{
      style:{
        width:'200px'
      }
    },
    ifShow: ({model}) => {
      if(model.hasWithAmount == 1) {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    label: '所需积分',
    field: 'integralValue',
    component: 'InputNumber',
    required: true,
  },
  {
    label: '库存数量',
    field: 'inventory',
    component: 'InputNumber',
    required: true,
    dynamicRules: () => rules.digits(true),
  },
  {
    label: '限购数量',
    field: 'limitNumber',
    component: 'InputNumber',
    defaultValue:1,
    required: true,
  },
  {
    label: '开始日期',
    field: 'expiryBeginTime',
    component: 'DatePicker',
    required: true,
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    label: '有效期',
    field: 'isHaveValidDay',
    component: 'Select',
    required: true,
    show:false,
    defaultValue: 2,
    componentProps: ({ formModel }) => {
      return {
        options: [
          { label: '终身有效', value: 2 },
          { label: '有有效期', value: 1 },
        ],
        onChange: (isHaveValidDay) => {
          formModel.validDay = null;
        },
      };
    },
  },
  {
    label: '有效期(天)',
    field: 'validDay',
    component: 'InputNumber',
    dynamicRules: () => rules.digits(true),
    required: true,
    itemProps:{
      extra:"说明:例如30天,用户领取兑换券30天到期",
    },
   /* ifShow: ({ model }) => {
      if (model.isHaveValidDay == 1) {
        return true;
      } else {
        return false;
      }
    },*/
  },

  {
    label: '优惠券ID',
    field: 'couponId',
    component: 'Input',
    show:false,
    required: false,
  },
  {
    label: '封面图',
    field: 'coverImg',
    component: 'ImageUpload',
    required: false,
  },
  {
    label: '详情页图片',
    field: 'goodsImg',
    component: 'ImageUpload',
    required: false,
  },

  {
    label: '商品描述',
    field: 'goodsDesc',
    componentProps:{
      height:400
    },
    component: 'TyEditor',
  },
  {
    label: '排序',
    field: 'goodsSort',
    component: 'InputNumber',
    required: true,
    defaultValue: 100,
  },
];
